package solutions.leetcode.easy

/**
 * @author lizhidong
 * <a href="https://leetcode.cn/problems/longest-common-prefix/">14. 最长公共前缀</a>
 */
class Solution14 {
    fun longestCommonPrefix(strs: Array<String>): String {
        var pre = strs[0]
        for (i in 1 until strs.size) {
            pre = pre.commonPrefixWith(strs[i])
        }
        return pre
    }
}

fun main() {
    println(Solution14().longestCommonPrefix(arrayOf(
        "flower",
        "flow",
        "flight",
    )))
}